package com.bygf.curve.utils;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * 用于曲线界面复制到剪切板的数据接口
 *
 * @author sunyupei
 */
public class ChartTransferable implements Transferable {

    //用于访问剪切板上的数据
    private DataFlavor imageFlavor = new DataFlavor(
            "image/x-java-image; class=java.awt.Image", "Image");
    //曲线界面截图对象
    private BufferedImage image;

    /**
     * 构造方法
     *
     * @param image 曲线界面截图对象
     */
    public ChartTransferable(BufferedImage image) {
        this.image = image;
    }

    @Override
    public DataFlavor[] getTransferDataFlavors() {
        return new DataFlavor[]{this.imageFlavor};
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
        return this.imageFlavor.equals(flavor);
    }

    @Override
    public Object getTransferData(DataFlavor flavor)
            throws UnsupportedFlavorException, IOException {
        return image;
    }
}
